package com.hznu.ez4life.modules.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.hznu.ez4life.modules.entity.Helpbuilding;
import com.hznu.ez4life.modules.entity.Helpitem;
import com.hznu.ez4life.modules.dao.HelpitemDao;
import com.hznu.ez4life.modules.service.HelpbuildingService;
import com.hznu.ez4life.modules.service.HelpitemService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DragonDoor
 * @since 2019-07-25
 */
@Service
public class HelpitemServiceImpl extends ServiceImpl<HelpitemDao, Helpitem> implements HelpitemService {

    @Autowired
    HelpbuildingService helpbuildingService;

    @Override
    public void addOne(Helpitem helpitem)
    {
        this.insert(helpitem);
        if(helpitem.getBuildingIds()!=null&&helpitem.getBuildingIds().length>0)
        {
            for(Integer buildingId : helpitem.getBuildingIds())
            {
                Helpbuilding helpbuilding = new Helpbuilding();
                helpbuilding.setBuildingId(buildingId);
                helpbuilding.setHelpitemId(helpitem.getId());
                helpbuildingService.insert(helpbuilding);
            }
        }
    }

    @Override
    public List<Helpitem> findBatchByUserid(Integer userId)
    {
        return this.baseMapper.findBatchByUserId(userId);
    }

    @Override
    public List<Helpitem> findBatchByCondition(Helpitem helpitem)
    {
        return baseMapper.findBatchByCondition(helpitem);
    }

    @Override
    public void removeOne(Integer id)
    {
        this.deleteById(id);
        helpbuildingService.delete(new EntityWrapper<Helpbuilding>().eq("helpitem_id",id));
    }

}
